//
//  OfficalNewsDetailViewController.m
//  GolfFriend
//
//  Created by Vescky on 14-3-16.
//  Copyright (c) 2014年 vescky.org. All rights reserved.
//

#import "OfficalNewsDetailViewController.h"
#import "DateUtility.h"
#import "LitePhotoCollectionView.h"

@interface OfficalNewsDetailViewController () {
    LitePhotoCollectionView *photosView;
}

@end

@implementation OfficalNewsDetailViewController

@synthesize newsInfo;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"官方新闻";
    [super customBackButton];
    [self initData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initData {
    labelTitle.text = [newsInfo objectForKey:@"title"];
    labelAuthorName.text = @"名媛荟官方";
    labelComment.text = [newsInfo objectForKey:@"comments"];
    labelZan.text = [newsInfo objectForKey:@"zan"];
    labelDate.text = getStringFromDate(@"yyyy-MM-dd", getDateFromString(@"yyyy-MM-dd HH:mm:ss", [newsInfo objectForKey:@"time"]));
//    tvContent.text = [newsInfo objectForKey:@"content"];
    [webView loadHTMLString:[newsInfo objectForKey:@"content"] baseURL:nil];
    
    NSArray *imgArr;
    if (isValueSet([newsInfo objectForKey:@"sourceLinks"])) {
        NSDictionary *sourceDict = [newsInfo objectForKey:@"sourceLinks"];
        if (isValueSet(sourceDict)) {
            imgArr = [sourceDict objectForKey:@"images"];
        }
    }
    
    float marginForContent = 5.0;
    if (imgArr && [imgArr count] > 0) {
        float imageHeight = 150;
        photosView = [[LitePhotoCollectionView alloc] init];
        [photosView setPhotoCollection:[[NSMutableArray alloc] initWithArray:imgArr]];
        [photosView setMargin: 2.0];
        [photosView setViewWidth:viewTools.frame.size.width];//与content同宽度
        [photosView setColCount:1];
        [photosView setScaleHDW:(float)imageHeight/320.0];
        [photosView.view setFrame:CGRectMake(viewTools.frame.origin.x,
                                             labelTitle.frame.origin.y + labelTitle.frame.size.height + 2 * marginForContent,
                                             viewTools.frame.size.width - 2 * marginForContent,
                                             imageHeight * [imgArr count])];
        [newScView addSubview:photosView.view];
    }
    
    
}

- (IBAction)btnAction:(id)sender {
    
}

@end
